<html lang="en">
<head>
    <title>酒店管理</title>
    <#include "../common/header.ftl">
        <script>
        $(function () {
            $(".changeBtn").click(function () {
                $("#editForm")[0].reset();
                var json = $(this).data("json");
                if (json){
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm select[name='hotel.id']").val(json.hotelId);
                    $("#editForm input[name='titel']").val(json.titel);
                    $("#editForm input[name='area']").val(json.area);
                    $("#editForm select[name='breakfast']").val(json.breakfast);
                    $("#editForm img").attr("src",json.coverUrl);
                    $("#editForm select[name='bed']").val(json.bed);
                    $("#editForm input[name='price']").val(json.price);
                }

                $("#editModal").modal("show");
            });
            $(".submitBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        window.location.reload();
                    }else(
                            $.messager.confirm("温馨提示","修改出错")
                    )
                })
            });

            $(".deleteBtn").click(function () {
                var json = $(this).data("json");
                var id = json.id;
                $.get("/room/saveOrUpdate.do",{id:id},function (data) {
                    if (data.success){
                        $.messager.confirm("温馨提示","退房成功")
                    }else{
                        $.messager.confirm("温馨提示","退房失败")
                    }
                })
            })

            $('#img').change(function () {
                var url = window.URL.createObjectURL(this.files[0]);
                $("#editForm img").attr("src",url)
            })
        });
    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="room">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">酒店房间管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/room/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">酒店名称:</label>
                    <select class="form-control" name="hotelId" id="hotel">
                        <option value="-1">--请选择--</option>
                            <#list hotels! as s>
                                <option value="${s.id}">${s.title}</option>
                            </#list>
                    </select>
                    <script>
                        $("#hotel").val(${(qo.hotelId)!})
                    </script>
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <button type="button" class="btn btn-info changeBtn"><span class="glyphicon glyphicon-plus"></span> 添加</button>
            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>类型</th>
                        <th>面积</th>
                        <th>床位</th>
                        <th>是否入住</th>
                        <th>入住时间</th>
                        <th>离店时间</th>
                        <th>客户</th>
                        <th>操作</th>
                    </tr>
                </thead>
               <#list (result.list)! as entity>
                   <tr>
                       <td>${entity.titel!}</td>
                       <td>${(entity.area)!}</td>
                       <td>${(entity.bedDisplay)!}</td>
                       <td>${(entity.typeDisplay)!}</td>
                       <td>${(entity.checkInTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                       <td>${(entity.checkOutTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                       <td>${(entity.user.nickName)!}</td>
                       <td>
                           <a href="javascript:;" class="changeBtn" data-json='${(entity.jsonString)!}'>修改</a>
                           <a href="javascript:;" class="deleteBtn" data-json='${(entity.jsonString)!}'>退房</a>
                       </td>
                   </tr>
               </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>
<!---大攻略编辑--->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">酒店客房编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/room/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" value="" name="id">
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">酒店名称：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="hotel.id" id="hotel">
                                <option value="-1">--请选择--</option>
                            <#list hotels! as s>
                                <option value="${s.id}">${s.title}</option>
                            </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">房间名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control"  name="titel" value="" placeholder="请输入房间名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">面积：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control"  name="area" value="" placeholder="请输入面积">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">早餐劵：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="breakfast" name="breakfast">
                                <option value="1">含</option>
                                <option value="0">不含</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img src="" alt="封面" width="200px;">
                            <input id="img" type="file" name="file">
                            <input type="hidden" name="coverUrl" value="" id="roomCoverUrl">
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">床型：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="bed" name="bed">
                                <option value="0">标准间</option>
                                <option value="1">双人间</option>
                                <option value="2">大床房</option>
                                <option value="3">总统套房</option>

                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">价格：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control"  name="price" value="" placeholder="请输入价格">
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary submitBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>